import java.util.Arrays;
import java.util.Comparator;

public class Solution436 {
    public int[] findRightInterval(int[][] intervals) {
        int[][] t=new int[intervals.length][3];
        for (int i=0;i<intervals.length;i++){
            t[i][0]=intervals[i][0];
            t[i][1]=intervals[i][1];
            t[i][2]=i;
        }
        Arrays.sort(t, Comparator.comparingInt(a -> a[0]));
        int[] ans=new int[intervals.length];
        for (int i=0;i<intervals.length;i++){
            int target=intervals[i][1];
            int a=-1,l=0,r=intervals.length-1;
            while (l<=r){
                int mid=(l+r)/2;
                if (t[mid][0]<target){
                    l=mid+1;
                }else{
                    a=mid;
                    r=mid-1;
                }
            }
            ans[i]=a==-1?-1:t[a][2];
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution436().findRightInterval(new int[][]{{3, 4}, {2, 3}, {1, 2}})));
    }
}
